<div class="col-md-12" style="margin-top:10px">
    <table id="attr_val_list" class="table table-hover">
        <tr>
            <th>属性值ID</th>
            <th>属性值名称</th>
            <th>操作</th>
        </tr>
        <?php foreach($data as $v):?>
        <tr>
            <td><?php echo $v['id']?></td>
            <td><?php echo $v['name']?></td>
            <td>
                <a href="javascript:;"
                   data-name="<?php echo $v['name']?>"
                   data-id="<?php echo $v['id']?>"
                   data-attr_id="<?php echo $attr_id?>"
                   class="btn btn-primary btn-xs update_val">修改</a>

                <a href="javascript:;" data-attr_id="<?php echo $attr_id?>" data-id="<?php echo $v['id']?>" class="btn btn-danger btn-xs delete_val">删除</a>
            </td>
        </tr>
        <?php endforeach;?>
    </table>
</div>
<script>

    $(function(){
        //删除属性值
        $('#attr_val_list').undelegate('.delete_val','click');
        $('#attr_val_list').delegate('.delete_val','click',function(){

            var _this = $(this);
            var data = {};
            data.attr_id = _this.data('attr_id');
            data.id = _this.data('id');
            layer.msg('确定删除吗？', {
                time: 0 //不自动关闭
                ,btn: ['删除', '关闭']
                ,yes: function(index){

                    layer.close(index);
                    var load = layer.load();
                    $.post('<?php echo U("Admin/Goods/Attr/deleteAttrVal")?>',{'data':data},function(result){

                        layer.close(load);

                        if(result.code == 200){

                            layer.msg(result.msg,{offset:0})
                            _this
                                    .parent()
                                    .parent()
                                    .fadeOut(200,function(){

                                        $(this).remove();

                                    })

                        }else{

                            layer.msg(result.msg,{offset:0,shift:6})

                        }

                    })

                }
            });


        });

        //修改属性值
        $('#attr_val_list').undelegate('.update_val','click');
        $('#attr_val_list').delegate('.update_val','click',function(){

            var _this = $(this);
            var data = {};
            data.id = _this.data('id');
            data.attr_id = _this.data('attr_id');
            var name = _this.data('name');

            layer.prompt(
                    {
                        title: '您将修改属性值: '+name,
                        formType: 0 //prompt风格，支持0-2
                    }
                    ,function(val){

                        data.name = val;

                        var load = layer.load();
                        $.post('<?php echo U("Admin/Goods/Attr/updateAttrVal")?>',{'data':data},function(result){

                            layer.close(load);

                            if(result.code == 200){

                                layer.msg(result.msg,{offset:0,time:1000},function(){

                                    _this
                                            .parent()
                                            .prev()
                                            .text(data.name);

                                });

                            }else{

                                layer.msg(result.msg,{offset:0,shift:6});

                            }


                        })

                    });

        });

    })
</script>